package com.wash.shoes.util;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import lombok.extern.log4j.Log4j2;

/**
 * @author lijianguo
 * @Date 31/08/2024 8:01 pm
 * 请输入类的简介
 **/
@Log4j2
public class AdminUserUtil {


    /**
     * @author lijianguo
     * @Date 31/08/2024
     * 用户id
     **/
    public static String getUserId() {
        LoginUser loginUser = getLoginUser();
        if (loginUser == null) {
            return null;
        } else {
            return String.valueOf(loginUser.getUser().getUserId());
        }
    }

    /**
     * @author lijianguo
     * @Date 31/08/2024
     * 用户名字
     **/
    public static String getUserName() {
        LoginUser loginUser = getLoginUser();
        if (loginUser == null) {
            return null;
        } else {
            return String.valueOf(loginUser.getUser().getNickName());
        }
    }

    /**
     * @author lijianguo
     * @Date 31/08/2024
     * 获取登录用户
     **/
    @Deprecated
    public static LoginUser getLoginUser() {
        try {
            return SecurityUtils.getLoginUser();
        } catch (Exception e) {
            log.info("login user not exist get null");
            return null;
        }
    }

    /**
     * @author lijianguo
     * @Date 31/08/2024
     * 获取登录用户
     **/
    public static String getLoginUserName() {
        try {
            return SecurityUtils.getLoginUser().getUser().getUserName();
        } catch (Exception e) {
            log.info("login user not exist get null");
            return null;
        }
    }

}
